package com.goodving.guli.view;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.androidquery.AQuery;
import com.androidquery.util.AQUtility;
import com.goodving.guli.R;
import com.goodving.guli.activity.MainFragmentActivity;
import com.goodving.guli.fragment.ViewPagerFragment;
import com.goodving.guli.model.DailyStats;
import com.goodving.guli.model.WeatherInfoModel;
import com.goodving.guli.service.StepMessage;
import com.goodving.guli.utility.C1465g;
import com.goodving.guli.utility.C1481u;
import com.goodving.guli.utility.C1965e;
import com.goodving.guli.utility.Constants;

/**
 * Created by john on 2015/11/18.
 */
public class TotalStatsCircleView extends FrameLayout {
    public static final int MSG_CHANGE_COLOR = 1024;
    public String TAG;
    private AnimatorSet bubbleAnimatorSet_;
    OnClickListener leftClickListener;
    private int mActivitySize;
    private TextView mAreaDate;
    private TextView mAreaTip;
    private ImageView mCardView_icon;
    private CircleMask mCircleMask;
    private ClickAnimationView mClickAnimationView;
    public Context mContext;
    private int mCurrentRadian;
    private DailyStats mDailyStats;
    private int mFinalRadian;
    private int mGoalSteps;
    private AQuery mQuery;
    private View mShareView;
    private int mSwitchType;
    private TextView mTemperature;
    private ImageView mTimeline;
    private WeatherInfoModel mWeatherInfoModel;
    private RelativeLayout mWeatherRelativeLayout;
    OnClickListener relativeClickListener;
    OnClickListener rightClickListener;
    private AnimatorSet shrinkAnimatorSet_;

    /* renamed from: cn.ledongli.ldl.view.StatsCircleView.1 */
    class C14991 implements OnClickListener {
        C14991() {
        }

        public void onClick(View view) {
            TotalStatsCircleView.this.mClickAnimationView.endAnimation();
            TotalStatsCircleView.this.mClickAnimationView.startAnimation();
        }
    }

    /* renamed from: cn.ledongli.ldl.view.TotalStatsCircleView.2 */
    class C15002 implements OnClickListener {
        C15002() {
        }

        public void onClick(View view) {
            if ((TotalStatsCircleView.this.mContext instanceof MainFragmentActivity) && (((MainFragmentActivity) TotalStatsCircleView.this.mContext).mFragment instanceof ViewPagerFragment)) {
//                ((ViewPagerFragment) ((MainFragmentActivity) TotalStatsCircleView.this.mContext).mFragment).tapLeftBtn();
            }
        }
    }

    /* renamed from: cn.ledongli.ldl.view.TotalStatsCircleView.3 */
    class C15013 implements OnClickListener {
        C15013() {
        }

        public void onClick(View view) {
            if ((TotalStatsCircleView.this.mContext instanceof MainFragmentActivity) && (((MainFragmentActivity) TotalStatsCircleView.this.mContext).mFragment instanceof ViewPagerFragment)) {
//                ((ViewPagerFragment) ((MainFragmentActivity) TotalStatsCircleView.this.mContext).mFragment).tapRightBtn();
            }
        }
    }

    /* renamed from: cn.ledongli.ldl.view.TotalStatsCircleView.4 */
    class C15024 implements OnClickListener {
        C15024() {
        }

        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.pageview_distance_container:
                    TotalStatsCircleView.this.mSwitchType = 0;
                    break;
                case R.id.pageview_calories_container:
                    TotalStatsCircleView.this.mSwitchType = 1;
                    break;
                case R.id.pageview_pm2_5_container:
                    TotalStatsCircleView.this.mSwitchType = 2;
                    break;
            }
            TotalStatsCircleView.this.updateCircle(true);
//            TotalStatsCircleView.this.switchTextColorAnimation();
        }
    }

    /* renamed from: cn.ledongli.ldl.view.TotalStatsCircleView.5 */
    class C15035 implements Animator.AnimatorListener {
        C15035() {
        }

        public void onAnimationStart(Animator animator) {
        }

        public void onAnimationRepeat(Animator animator) {
        }

        public void onAnimationEnd(Animator animator) {
            TotalStatsCircleView.this.shrinkAnimatorSet_.start();
        }

        public void onAnimationCancel(Animator animator) {
        }
    }

//    /* renamed from: cn.ledongli.ldl.view.TotalStatsCircleView.6 */
//    class C15046 implements Runnable {
//        final /* synthetic */ String val$path;
//
//        C15046(String str) {
//            this.val$path = str;
//        }
//
//        public void run() {
//            try {
//                C1470k.m11993a(this.val$path, TotalStatsCircleView.this.shareCreateImage());
//            } catch (Exception e) {
//            }
//        }
//    }

    public class ClickAnimationView extends View implements ValueAnimator.AnimatorUpdateListener {
        private ValueAnimator bounceAnim_;
        int cricleWdithPx_;
        private final Paint paint_;
        private int radius;
        private final RadiusShapeHolder radiusShapeHolder;

        class RadiusShapeHolder {
            private int radius;

            public void setRadius(int i) {
                this.radius = i;
            }

            public int getRadius() {
                return this.radius;
            }

            public RadiusShapeHolder(int i) {
                this.radius = 0;
                this.radius = i;
            }
        }

        public ClickAnimationView(Context context) {
            super(context);
            this.cricleWdithPx_ = 0;
            this.radius = 0;
            this.bounceAnim_ = null;
            this.radius = AQUtility.dip2pixel(context, 38.0f);
            this.cricleWdithPx_ = AQUtility.dip2pixel(context, CircleMask.CIRCLE_MASK_WIDTH);
            this.radiusShapeHolder = new RadiusShapeHolder(this.radius * 2);
            this.paint_ = new Paint();
            this.paint_.setStyle(Paint.Style.STROKE);
            this.paint_.setColor(context.getResources().getColor(R.color.grep_ripple));
        }

        private void createAnimation() {
            if (this.bounceAnim_ == null) {
                this.bounceAnim_ = ObjectAnimator.ofInt(this.radiusShapeHolder, "radius", new int[]{this.radius, this.radius * 2});
                this.bounceAnim_.setDuration(700);
                this.bounceAnim_.setInterpolator(new AccelerateDecelerateInterpolator());
                this.bounceAnim_.addUpdateListener(this);
            }
        }

        public void startAnimation() {
            createAnimation();
            this.bounceAnim_.start();
        }

        public void cancelAnimation() {
            createAnimation();
            this.bounceAnim_.cancel();
        }

        public void endAnimation() {
            createAnimation();
            this.bounceAnim_.end();
        }

        protected void onDraw(Canvas canvas) {
            canvas.save();
            int radius = this.radiusShapeHolder.getRadius();
            this.paint_.setStrokeWidth((float) ((this.radius * 2) - ((radius - this.radius) * 2)));
            canvas.drawCircle((float) (this.cricleWdithPx_ / 2), (float) (this.cricleWdithPx_ / 2), (float) radius, this.paint_);
            canvas.restore();
        }

        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            invalidate();
        }
    }

    public void updateStepNotification(StepMessage stepMessage) {
        ((AQuery) this.mQuery.id((int) R.id.pageview_bubble)).visibility(0);
        switch (1) {//stepMessage.f6081g
            case 1 /*1*/:
                startFakeStepAnimator(((AQuery) this.mQuery.id((int) R.id.pageview_bubble)).getView(), 100);//TBD stepMessage.f6082h
                break;
            case 2 /*2*/:
                startFakeStepAnimator(((AQuery) this.mQuery.id((int) R.id.pageview_bubble)).getView(), 10);
                break;
            case 3 /*3*/:
                startFakeStepAnimator(((AQuery) this.mQuery.id((int) R.id.pageview_bubble)).getView(), 10);
                fadeOutFullCircle();
                break;
            default:
                break;
        }
    }

    public TotalStatsCircleView(Context context, DailyStats dailyStats) {
        super(context);
        this.TAG = TotalStatsCircleView.class.getSimpleName();
        this.mCurrentRadian = 0;
        this.mFinalRadian = 0;
        this.mGoalSteps = C1465g.aQ;; //TBD hardcode target here
        this.mActivitySize = 0;
        this.mSwitchType = 0;
        this.leftClickListener = new C15002();
        this.rightClickListener = new C15013();
        this.relativeClickListener = new C15024();
        this.bubbleAnimatorSet_ = new AnimatorSet();
        this.shrinkAnimatorSet_ = new AnimatorSet();
        this.mContext = context;
        this.mDailyStats = dailyStats;

        initView();
        updateData();

    }

    public void initView() {
        View inflate = LayoutInflater.from(getContext()).inflate(R.layout.fragment_home, null);
        addView(inflate);
        this.mQuery = new AQuery(inflate);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.outHeight = AQUtility.dip2pixel(getContext(), 280.0f);
        options.outWidth = AQUtility.dip2pixel(getContext(), 320.0f);
//        this.mWeatherRelativeLayout = (RelativeLayout) ((AQuery) this.mQuery.id((int) R.id.weather_card)).getView();
        this.mCardView_icon = (ImageView) ((AQuery) this.mQuery.id((int) R.id.cardview_icon)).getView();
//        this.mTemperature = (TextView) ((AQuery) this.mQuery.id((int) R.id.tv_weather_temperature)).getView();
//        this.mAreaDate = (TextView) ((AQuery) this.mQuery.id((int) R.id.tv_weather_area_date)).getView();
//        this.mAreaTip = (TextView) ((AQuery) this.mQuery.id((int) R.id.tv_weather_area_tip)).getView();
//        this.mTimeline = (ImageView) ((AQuery) this.mQuery.id((int) R.id.timeline_vertical_line)).getView();
        this.mShareView = findViewById(R.id.rt_circle_image);
        RelativeLayout relativeLayout = (RelativeLayout) ((AQuery) this.mQuery.id((int) R.id.pageview_circle_animation_rl)).getView();
        this.mClickAnimationView = new ClickAnimationView(getContext());
        ObjectAnimator.ofFloat(((AQuery) this.mQuery.id((int) R.id.pageview_bubble)).getView(), "scaleX", new float[]{0.0f}).setDuration(1).start();
        ObjectAnimator.ofFloat(((AQuery) this.mQuery.id((int) R.id.pageview_bubble)).getView(), "scaleY", new float[]{0.0f}).setDuration(1).start();
        this.mCircleMask = new CircleMask(getContext());
        relativeLayout.addView(this.mCircleMask);
        relativeLayout.addView(this.mClickAnimationView);
        Typeface createFromAsset = Typeface.createFromAsset(getContext().getAssets(), "fonts/akzidenzgrotesklightcond.ttf");
        ((AQuery) this.mQuery.id((int) R.id.pageview_left_btn)).clicked(this.leftClickListener);
//        if (LdlDate.m8856a().m8876i().getTime() == LdlDate.m8859a(this.mDailyStats.m8682u().getTime()).m8876i().getTime()) {
//            ((AQuery) this.mQuery.id((int) R.id.pageview_right_btn)).invisible();
//        } else {
//            ((AQuery) ((AQuery) this.mQuery.id((int) R.id.pageview_right_btn)).visible()).clicked(this.rightClickListener);
//        }
        ((AQuery) this.mQuery.id((int) R.id.pageview_circle_big_tv)).typeface(createFromAsset);
        ((AQuery) this.mQuery.id((int) R.id.pageview_activity_time_value)).typeface(createFromAsset);
        ((AQuery) this.mQuery.id((int) R.id.pageview_calories_value)).typeface(createFromAsset);
        ((AQuery) this.mQuery.id((int) R.id.pageview_distance_value)).typeface(createFromAsset);
        ((AQuery) this.mQuery.id((int) R.id.pageview_circle_rl)).clicked(new C14991());
        ((AQuery) this.mQuery.id((int) R.id.pageview_distance_container)).clicked(this.relativeClickListener);
        ((AQuery) this.mQuery.id((int) R.id.pageview_calories_container)).clicked(this.relativeClickListener);
        ((AQuery) this.mQuery.id((int) R.id.pageview_pm2_5_container)).clicked(this.relativeClickListener);
    }

    public void switchTextColorAnimation() {
        Object textView = ((AQuery) this.mQuery.id((int) R.id.pageview_distance_value)).getTextView();
        Object textView2 = ((AQuery) this.mQuery.id((int) R.id.pageview_distance_title)).getTextView();
        int color = getContext().getResources().getColor(R.color.light_grey);
        int color2 = getContext().getResources().getColor(R.color.orange_share);
        switch (this.mSwitchType) {
            case 0 /*0*/:
                textView = ((AQuery) this.mQuery.id((int) R.id.pageview_distance_value)).getTextView();
                textView2 = ((AQuery) this.mQuery.id((int) R.id.pageview_distance_title)).getTextView();
                break;
            case 1 /*1*/:
                textView = ((AQuery) this.mQuery.id((int) R.id.pageview_calories_value)).getTextView();
                textView2 = ((AQuery) this.mQuery.id((int) R.id.pageview_calories_title)).getTextView();
                break;
            case 2 /*2*/:
                textView = ((AQuery) this.mQuery.id((int) R.id.pageview_activity_time_value)).getTextView();
                textView2 = ((AQuery) this.mQuery.id((int) R.id.pageview_activity_time_title)).getTextView();
                break;
        }
        ValueAnimator ofInt = ObjectAnimator.ofInt(textView, "textColor", new int[]{color2, 0xFF000000});
        ValueAnimator ofInt2 = ObjectAnimator.ofInt(textView2, "textColor", new int[]{color2, color});
        ofInt.setEvaluator(new ArgbEvaluator());
        ofInt2.setEvaluator(new ArgbEvaluator());
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(new Animator[]{ofInt, ofInt2});
        animatorSet.setDuration(1000);
        animatorSet.start();
    }

    private void updateData() {
        this.mGoalSteps = C1481u.m12082d().getInt(C1465g.aq, C1465g.aQ);
        updateCircle(false);
        updateCircleMask(this.mCurrentRadian, this.mFinalRadian, false);
    }

    private void updateCircle(boolean z) {
        if (this.mQuery == null || this.mDailyStats == null) {
//            C1472m.m12013a(this.TAG, "mQuery is null or dailyStats is null");
            return;
        }

        CharSequence charSequence;

        ((AQuery) this.mQuery.id((int) R.id.pageview_circle_unit_tv)).text(getContext().getResources().getString(R.string.steps));
        double t = (double) this.mDailyStats.getGoalStep();
        double f = (double) this.mDailyStats.getStepCnt();
        ((AQuery) this.mQuery.id((int) R.id.pageview_circle_big_tv)).text("" + ((int) f));
        ((AQuery) this.mQuery.id((int) R.id.pageview_circle_goalunit_tv)).text("目标" + ((int) t));
        this.mCurrentRadian = this.mFinalRadian;
        this.mFinalRadian = (int) (((double) (Math.round(f) * 360)) / t);
        if (this.mFinalRadian >= 360 || (z && this.mCurrentRadian >= 360)) {
            if (this.mFinalRadian >= 360) {
                fadeInFullCircle();
                this.mFinalRadian = 360;
            } else {
                fadeOutFullCircle();
            }
        }

    }

    private void fadeInFullCircle() {
        ObjectAnimator.ofFloat(((AQuery) this.mQuery.id((int) R.id.circle_image_full)).getView(), "alpha", new float[]{0.0f, C1965e.f9059c}).setDuration(250).start();
    }

    private void fadeOutFullCircle() {
        ObjectAnimator.ofFloat(((AQuery) this.mQuery.id((int) R.id.circle_image_full)).getView(), "alpha", new float[]{C1965e.f9059c, 0.0f}).setDuration(250).start();
    }

    private void updateCircleMask(int i, int i2, boolean z) {
        if (this.mCircleMask != null) {
            this.mCircleMask.updateCircleMask(i, i2, z);
        }
    }

    private void startFakeStepAnimator(View view, int i) {
        this.bubbleAnimatorSet_.cancel();
        this.shrinkAnimatorSet_.cancel();
        this.bubbleAnimatorSet_ = new AnimatorSet();
        this.shrinkAnimatorSet_ = new AnimatorSet();
        ObjectAnimator ofFloat;
        ObjectAnimator ofFloat2;
        ObjectAnimator ofFloat3;
        if (i < 10) {
            ofFloat = ObjectAnimator.ofFloat(view, "scaleX", new float[]{(float) ((((double) i) * 0.1d) + 0.1d)});
            ofFloat2 = ObjectAnimator.ofFloat(view, "scaleY", new float[]{(float) ((((double) i) * 0.1d) + 0.1d)});
            ofFloat3 = ObjectAnimator.ofFloat(view, "alpha", new float[]{(float) (Constants.DEFAULT_INTENSITY - (((double) i) * 0.1d))});
            this.bubbleAnimatorSet_.playTogether(new Animator[]{ofFloat, ofFloat2, ofFloat3});
            this.bubbleAnimatorSet_.setInterpolator(new AccelerateDecelerateInterpolator());
            this.bubbleAnimatorSet_.setDuration(200);
            ofFloat = ObjectAnimator.ofFloat(view, "scaleX", new float[]{0.0f});
            ofFloat2 = ObjectAnimator.ofFloat(view, "scaleY", new float[]{0.0f});
            ofFloat3 = ObjectAnimator.ofFloat(view, "alpha", new float[]{C1965e.f9059c});
            this.shrinkAnimatorSet_.playTogether(new Animator[]{ofFloat, ofFloat2, ofFloat3});
            this.shrinkAnimatorSet_.setDuration(1800);
        } else {
            this.bubbleAnimatorSet_.play(ObjectAnimator.ofFloat(view, "alpha", new float[]{0.0f}));
            this.bubbleAnimatorSet_.setDuration(200);
            ofFloat = ObjectAnimator.ofFloat(view, "scaleX", new float[]{0.0f});
            ofFloat2 = ObjectAnimator.ofFloat(view, "scaleY", new float[]{0.0f});
            ofFloat3 = ObjectAnimator.ofFloat(view, "alpha", new float[]{C1965e.f9059c});
            this.shrinkAnimatorSet_.playSequentially(new Animator[]{ofFloat, ofFloat2, ofFloat3});
            this.shrinkAnimatorSet_.setDuration(1);
        }
        this.bubbleAnimatorSet_.addListener(new C15035());
        this.bubbleAnimatorSet_.start();
    }

    public void updateStatsCircle(DailyStats dailyStats) {
        this.mDailyStats = dailyStats;
        updateData();
    }
}
